import { HttpClient } from '@angular/common/http';
import { Component, Input, OnInit } from '@angular/core';
import { res } from 'src/app/common/Interface';

@Component({
  selector: 'app-in-log',
  templateUrl: './in-log.component.html',
  styleUrls: ['./in-log.component.less'],
})
export class InLogComponent implements OnInit {
  @Input('commodity_id') commodity_id: number;

  constructor(private http: HttpClient) {}

  ngOnInit() {
    this.getList();
  }
  condition = {
    pageSize: 5,
    pageNo: 1,
  };
  total = 0;
  getList() {
    this.http
      .post('/inLog/list', {
        commodity_id: this.commodity_id,
        ...this.condition,
      })
      .subscribe(({ code, data, msg }: res) => {
        if (code == 200) {
          const { total } = data;
          this.total = total;
          this.listOfData = data.data;
        }
      });
  }
  listOfData = [];

  startTime: number = 0;
  timeOut: any = null;
  touchstart(data: any) {
    this.startTime = Date.now();
    this.timeOut = setTimeout(() => {
      data.show = true;
      clearTimeout(this.timeOut);
    }, 1000);
  }

  clickMe(data: any) {
    confirm('确定要删除这条记录吗？');
    data.show = false;
  }

  touchend() {
    if (Date.now() - this.startTime < 1000) {
      clearTimeout(this.timeOut);
    }
  }
}
